// pages/goods/catched_list/catched_list.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    catchedGoodsList: [],
    isShowList: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function (options) {
    //页面填充完整
    this.setData({
      pageHeight: app.globalData.pageHeight - 2
    })
  },
  
  onShow:function(options){
    this.getCatchedOptions();
  },

  //获取更多数据
  loadMoreData: function (e) {
    let resArr = [];
    if (e.detail.data.length > 0) {
      for (let item of e.detail.data) {
        let obj = {
          goods_id: item.order_id,
          image: item.goods[0].goods_image,
          goods_name: item.goods[0].goods_name,
          price: item.goods[0].sell_price,
          status: item.status,
        }
        resArr.push(obj);
      }
    }
    this.setData({
      catchedGoodsList: resArr,
    })
  },

  //获取参数
  getCatchedOptions: function () {
    var scrollListHeight = app.globalData.windowHeight;
    var catchedGoodsOptions = {
      list_id: 'catchedGoods',
      url: '/api/index.php?app=account&act=drag_list',
    }
    this.setData({
      scrollListHeight: scrollListHeight,
      catchedGoodsOptions: catchedGoodsOptions
    })
  },

  //跳转到去做任务的列表
  linktoTask: function () {
    wx.switchTab({
      url: '../../task/mainpage/mainpage',
    })
  },

  /**
   * 领取商品
   */
  receiveGoods: function (e) {
    var target = e.detail.target;
    if (target.status == 10) {
      wx.navigateTo({
        url: '../receive_info/receive_info?order_id=' + target.goods_id,//这里的goods_id 对应的是order_id
      })
    } else if (target.status >= 20) {
      //查看物流信息
      wx.navigateTo({
        url: '../exchanged_info/exchanged_info?order_id=' + target.goods_id,//这里的goods_id 对应的是order_id
      })
    } else if (target.status == 11) {
      wx.navigateTo({
        url: '../../my/myorder/orderInfo/orderInfo?order_id=' + target.goods_id,//这里的goods_id 对应的是order_id
      })
    }
  }
})